<template>
    <base-dialog
            v-bind="$attrs"
            v-on="$listeners"
            :title="dialogTitle">
        <el-tabs tab-position="left" class="detail-tab"
                 v-model="activeName" v-if="row.ticket||showTab">
            <el-tab-pane label="概况" name="first" :key="1">
                <scroll-panel :height="height">
                    <slot :data="row"></slot>
                </scroll-panel>
            </el-tab-pane>
            <slot name="otherItem"></slot>
            <el-tab-pane label="流程" v-if="row.ticket&&hasPermissions('viewflow')" name="second" :key="2">
              <div style="overflow-y: scroll;height: 100%;">
                    <right-steps :row="row" :is-all="true"></right-steps>
              </div>
            </el-tab-pane>
            <el-tab-pane label="动态" name="third" v-if="showWorkFlow&&flowInfo.show_flow" :key="4">
                <scroll-panel :height="height">
                <top-step :id="row.ticket" @getCurrentStateId="getCurrentStateId" direction="vertical"></top-step>
                </scroll-panel>
            </el-tab-pane>
            <el-tab-pane label="流程图" :lazy="true" name="forth" v-if="showWorkFlow&&flowInfo.show_flow"  :key="5">
                <scroll-panel :height="height">
                <process
                        :id="flowInfo.workflow_id"
                        :current_state_id="current_state_id"
                        v-if="flowInfo.workflow_id"
                ></process>
                </scroll-panel>
            </el-tab-pane>
        </el-tabs>
        <slot v-else :data="row">
        </slot>
        <span slot="footer" class="dialog-footer" v-if="showFooter">
            <slot name="other-btn">
            </slot>
            <slot name="footer">
                <template v-if="isEdit">
                    <el-button @click="handleClose">取 消</el-button>
<!--                     <el-button @click="onSubmit(1)" v-if="this.row.is_draft==1">存草稿</el-button>-->
                    <el-button type="primary" @click="onSubmit(0)">{{this.row.is_draft==1?'提 交':"保 存"}}</el-button>
                </template>
                <template v-else-if="row.id">
                    <el-button @click="handleClose">关 闭</el-button>
                    <template v-for="(btn, index) in btnList">
                        <el-button :key="index" @click="doSomething(btn)" v-if="btn.attribute_type_id==1" type="primary"
                                   style="float: right">{{btn.transition_name}}</el-button>
                         <el-button :key="index" @click="doSomething(btn)" v-else>{{btn.transition_name}}</el-button>
                    </template>
                </template>
                <template v-else-if="row.is_draft>1">
                     <el-button @click="handleClose">取 消</el-button>
                    <el-button type="primary" @click="onSubmit(row.is_draft)">提 交</el-button>
                </template>
                <template v-else>
                    <el-button @click="handleClose">取 消</el-button>
<!--                    <el-button @click="onSubmit(1)">存草稿</el-button>-->
                    <el-button type="primary" @click="onSubmit(0)">提 交</el-button>
                </template>
            </slot>
        </span>
        <approver-list :visible.sync="approverInfo.visible" v-if="approverInfo.visible" @callback="approverInfo.callback" :data-list="approverInfo.dataList"  :showCheckbox="approverInfo.showCheckbox"></approver-list>
        <component :is="eventDialogInfo.component" v-if="eventDialogInfo.visible" @callback="eventDialogInfo.callback" :visible.sync="eventDialogInfo.visible"></component>
        <suggestion-common-dialog  v-if="suggestionInfo.visible" :visible.sync="suggestionInfo.visible" v-model="suggestionInfo.msg" @callback="suggestionInfo.callback" :btn="currBtn"></suggestion-common-dialog>
    </base-dialog>
</template>

<script>
    import RightSteps from "@/components/WorkFlowsDialog/Case/RightSteps";
    // import ApproverList from "@/WorkFlowsDialog/Case/ApproverList";
    import ScrollPanel from "../Common/ScrollPanel";
    import eventBus from "@/utils/eventBus";
    import TopStep from "../../views/workManagement/components/topStep";
    import Process from "../../views/workManagement/components/process";
    import SimpleSuggestionDialog from "./Case/SimpleSuggestionDialog";
    import BaseDialog from '../Common/BaseDialog'
    import ButtonHandle from "@/mixins/ButtonHandle"
    export default {
        name: "WorkflowSimpleDialog",
        components: { BaseDialog, SimpleSuggestionDialog, Process, TopStep,ScrollPanel, RightSteps},
        mixins:[ButtonHandle],
        props: {
            width: {
                type: String,
                default: "1000px"
            },
            height: {
                type: String,
                default: "600px"
            },
            disabled: {
                type: Boolean,
                default: false
            },
            title: {
                type: String,
                default: ""
            },
            showTab:{
                type:Boolean,
                default:false
            }
        },
        data() {
            return {
                activeName: "first",
                key: "",
                btn: {},
                msg: "",
                btnMsgtitle: "",
                dept_ids:[],
                current_state_id: "",
                showFooter:true
            };
        },
        created() {
            console.log("---------------this.row",this.row)
            eventBus.$on("closeDetailDialog", (isReload) => {
                if(isReload){
                    this.$emit("reloadList")
                }
                this.handleClose()
            });
            eventBus.$on("hideFooter", () => {
               this.showFooter = false
            });
        },
        computed: {
            showWorkFlow() {
                return this.row.ticket
            },
            dialogTitle() {
                if (this.title) return this.title;
                else {
                    if (this.isEdit) {
                        return "修改-"+this.row.title
                    } else if (this.row.id) {
                        return "查看-"+this.row.title
                    } else {
                        return "新增-"+this.$route.meta.title
                    }
                }

            },
            isEdit() {
                return (this.row&&this.row.is_edit&&!this.disabled) || (this.row&&this.row.id && !this.row.ticket&&!this.disabled)
            }
        },
        methods: {
            getCurrentStateId(id) {
                this.current_state_id = id;
            },
            handleClose(done) {
                this.$emit("update:visible", false)
            },
            onSubmit(status) {
                this.$emit("submit", status)
            },
        }
    };
</script>
<style lang="scss" scoped>
  @import "../../assets/styles/workflow";
</style>
